import asyncio
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), "/root/work/arcfox-crawler"))
from com.arcfox.yiqing.task.manager.yiqing_task_manager import TaskManager
from com.arcfox.yiqing.spider.city_code_spider import CityCodeSpider
from com.arcfox.yiqing.spider.risk_area_spider import RiskAreaSpider
from com.arcfox.yiqing.spider.yiqing_data_spider import YiQingDataSpider


class YiQingService:

    def __init__(self):
        self.city_code_spider = CityCodeSpider()
        self.yiqing_data_spider = YiQingDataSpider()
        self.risk_area_spider = RiskAreaSpider()
        self.task_manager = TaskManager()

    async def start(self):
        tasks = [
            asyncio.create_task(self.city_code_spider.start_crawl()),
            asyncio.create_task(self.risk_area_spider.start_crawl()),
        ]
        await asyncio.gather(*tasks)
        await self.task_manager.add_tasks()
        await self.yiqing_data_spider.start_crawl()


if __name__ == "__main__":
    asyncio.run(YiQingService().start())
